package com.nsu.konus.control;

import java.io.IOException;
import java.net.UnknownHostException;
import java.nio.channels.ClosedChannelException;

public class KonusSender {
	
	private static String MOUNT = "mount";
	
	public KonusSender() {
		sender = new CommandsSender(port);
	}
	
	public void start() throws UnknownHostException, IOException {
		sender.start();
	}
	
	public void findDosboxClient() throws ClosedChannelException, IOException {
		sender.findDosboxClient();
	}
	
	public void mount(String disk, String path) throws IOException, InterruptedException {
		sendString(MOUNT + " " + disk + " " + path);
	}
	
	public void remount(String disk) throws IOException, InterruptedException {
		sendString(MOUNT + " -u " + disk);
	}
	
	public void run(String command) throws IOException, InterruptedException {
		sendString(command);
	}
	
	public void sendString(String s) throws IOException, InterruptedException {
		sender.sendCommand("!" + s);
		sender.sendCommand("enter");
	}
	
	public void sendWithSleep(int sleepTime, String command) throws IOException, InterruptedException {
		sender.sendCommand(command);
		Thread.sleep(sleepTime);
	}
	
	public void sendStringWithSleep(int sleepTime, String command) throws IOException, InterruptedException {
		sendString(command);
		Thread.sleep(sleepTime);
	}
	
	private int port = 7788;
	private CommandsSender sender;
}
